<?php

/**
 * This is the model class for table "member".
 *
 * The followings are the available columns in table 'member':
 * @property integer $id
 * @property string $last_name
 * @property string $first_name
 * @property string $type
 * @property string $specialization
 * @property string $email
 * @property string $address
 * @property string $contact
 * @property string $website_link
 * @property string $link
 * @property string $photo
 * @property integer $role_id
 *
 * The followings are the available model relations:
 * @property Role $role
 * @property SucessfulCase[] $sucessfulCases
 * @property Testimony[] $testimonies
 */
class Member extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Member the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'member';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('role_id', 'required'),
			array('role_id', 'numerical', 'integerOnly'=>true),
			array('last_name, first_name, type, specialization, email, address, contact, website_link, link', 'length', 'max'=>45),
			array('photo', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, last_name, first_name, type, specialization, email, address, contact, website_link, link, photo, role_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'role' => array(self::BELONGS_TO, 'Role', 'role_id'),
			'sucessfulCases' => array(self::HAS_MANY, 'SucessfulCase', 'member_id'),
			'testimonies' => array(self::HAS_MANY, 'Testimony', 'member_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'last_name' => 'Last Name',
			'first_name' => 'First Name',
			'type' => 'Type',
			'specialization' => 'Specialization',
			'email' => 'Email',
			'address' => 'Address',
			'contact' => 'Contact',
			'website_link' => 'Website Link',
			'link' => 'Link',
			'photo' => 'Photo',
			'role_id' => 'Role',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('specialization',$this->specialization,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('contact',$this->contact,true);
		$criteria->compare('website_link',$this->website_link,true);
		$criteria->compare('link',$this->link,true);
		$criteria->compare('photo',$this->photo,true);
		$criteria->compare('role_id',$this->role_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}